#include<bits/stdc++.h>
using namespace std;

//!!!双指针法

class Solution {
public:
    int maxArea(vector<int>& height) {
        int i = 0; int j = height.size() - 1;
        int maxVol = 0;
        while(i < j){
            maxVol = max(min(height[i], height[j])*(j-i), maxVol);
            if(height[i] < height[j]) ++i;
            else --j;
        }
        return maxVol;
    }
};

int main(){
    vector<int> height = {1,8,6,2,5,4,8,3,7};
    Solution solution;
    cout<<solution.maxArea(height);
    return 0;
}